/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.araujogrosz.fractalcore;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

/**
 *
 * @author renatogrosz@gmail.com
 */
public class RFractal {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        JanelaThreadFractal j = createJanelaThreadFractal();        
        j.setVisible(true);
        j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
        //k();
    }
       
    public static JanelaThreadFractal createJanelaThreadFractal(){
        int imageSize = 480;        
        ColorMatrix colorMatrix = new ColorMatrixFactory().getColorMatrix();                                       
        JanelaThreadFractal retorno = new JanelaThreadFractal(imageSize, colorMatrix);
        return retorno;
    }
    
    public static ThreadFractal createThreadFractal(){
        FractalExporter fractalExporter = new FractalExporter();
        return fractalExporter.createThreadFractal();
    }
    
    
    public static void k() throws IOException{
        ColorMatrixImpl colorMatrix = new ColorMatrixImpl(0, 0, 0);
        colorMatrix.addRed(255, 50);
        colorMatrix.addRed(0, 277);
        colorMatrix.addRed(255, 577);
        colorMatrix.addRed(0, 1277);


        colorMatrix.addGreen(255, 193);
        colorMatrix.addGreen(0, 233);
        colorMatrix.addGreen(255, 733);
        colorMatrix.addGreen(0, 1233);


        colorMatrix.addBlue(255, 111);
        colorMatrix.addBlue(0, 333);
        colorMatrix.addBlue(255, 705);
        colorMatrix.addBlue(0, 1205);

        int imageSize = 400;
        
        ImagePainter imagePainter = new ImagePainter(imageSize, colorMatrix);
        
        CalcFract calcFract = new CalcFract(imageSize);
        calcFract.setPrinter(imagePainter);
        calcFract.setIterations(200);
        calcFract.zoom(80, 170, 150);
        calcFract.calc();
        
        File f= new File("/output/image.jpg");
        OutputStream out = new FileOutputStream(f);

        ImageIO.write(imagePainter.getBuf(), "JPG", out);
        
    }
}
